package com.hongyan.dao;

import com.hongyan.bean.Admin;
import com.hongyan.bean.Person;
import com.hongyan.bean.Student;
import com.hongyan.bean.Teacher;
import com.hongyan.util.JDBCUtils;

import java.sql.SQLException;
import java.util.List;

public class LoginDao {
    public static Person login(String username, String password, int type) {

        if (type == 0) {
            List<Student> query = JDBCUtils.queryBycondition("select * from s_info where s_name =? and password = ?", Student.class, username, password);
            if (!query.isEmpty()) {
                return query.get(0);
            } else {
                return null;
            }
        } else if (type == 1) {
            List<Teacher> query = JDBCUtils.queryBycondition("select * from t_info where t_name =? and password = ?", Teacher.class, username, password);
            if (!query.isEmpty()) {
                return query.get(0);
            } else {
                return null;
            }
        } else if (type == 2) {
            List<Admin> query = JDBCUtils.queryBycondition("select * from a_info where a_name =? and password = ?", Admin.class, username, password);
            if (!query.isEmpty()) {
                return query.get(0);
            } else {
                return null;
            }
        } else {
            return null;
        }


    }
}
